package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Slf4j
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;


    /**
     * 查询所有护理等级
     * @return
     */
    @GetMapping("/listAll")
    public ResponseResult<NursingLevelVo> getListAll() {
        logger.info("查询所有护理等级");
        // 调用Service层查询所有护理等级
        List<NursingLevelVo> nursingLevelList = nursingLevelService.getListAll();
        // 响应数据
        return success(nursingLevelList);
    }

    /**
     * 新增护理等级
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        log.info("新增护理等级: {}",nursingLevelDto);

        // 调用Service层新增护理等级
        nursingLevelService.addNursingLevel(nursingLevelDto);
        // 响应数据
        return success();
    }

    /**
     * 条件分页查询护理等级
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String name,
            Integer status) {
    	// 调用Service层条件分页查询护理等级
        PageResponse<NursingLevelVo> NursingLevelList = nursingLevelService.getByPage(pageNum,pageSize,name,status);
        // 响应数据
        return success(NursingLevelList);
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Integer id) {
        // 调用Service层根据id查询护理等级
        NursingLevelVo nursingLevel = nursingLevelService.getById(id);
        // 响应数据
        return success(nursingLevel);
    }

    /**
     * 修改护理等级
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        // 调用Service层修改护理等级
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        // 响应数据
        return success();
    }

    /**
     * 删除护理等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
    	// 调用Service层删除护理等级
        nursingLevelService.deleteById(id);
        // 响应数据
        return success();
    }

    /**
     * 启用禁用护理等级
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStop(@PathVariable Integer id, @PathVariable Integer status) {
        // 调用Service层启用禁用护理等级
        nursingLevelService.startOrStop(id, status);
        // 响应数据
        return success();
    }
}
